<?php

namespace App\Service\UserCenter\v1_1_4;

use App\Helpers\AliyunUtil;
use App\Model\Service\CacheService;
use App\Model\Setting\SettingUserLevel;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 等级详情（财富，魅力）
 */
class LevelDetailService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $levelType = $this->request->input('level_type', 1);
        $profile = UserProfile::getProfile($userId);
        $levelType = UserProfile::checkRoleHost($profile->role) ? 2 : 1;
        $levelValue = $levelType == 1 ? $profile->rich_value : $profile->charm_value;
        $ret = [
            'title' => $levelType == 1 ? '财富等级' : '魅力等级',
            //豪气值或者魅力值
            'level_value' => $levelValue,
            //等级值
            'level' => SettingUserLevel::getUserLevel($profile),
            //距离升级的等级值
            'level_value_distance' => SettingUserLevel::getDistance($levelType, $levelValue),
            //特权
            'desc' => [
                [
                    'title' => '等级特权',
                    'list' => $levelType == 1 ? [
                        ['name' => '等级名片', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/p-01.png'],
                        ['name' => '优先通话', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/p-02.png'],
                        ['name' => '优质特权', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/p-03.png'],
                        ['name' => '更多特权', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/p-more.png'],
                    ] : [
                        ['name' => '等级名片', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/p-f-01.png'],
                        ['name' => '收费升级', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/p-f-02.png'],
                        ['name' => '优质推荐', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/p-f-03.png'],
                        ['name' => '更多特权', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/p-f-more.png'],
                    ]
                ],
                [
                    'title' => '如何升级',
                    'list' => $levelType == 1 ? [
                        ['name' => '拨打语音', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/h-01.png'],
                        ['name' => '拨打视频', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/h-02.png'],
                        ['name' => '发送私信', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/h-04.png'],
                        ['name' => '赠送礼物', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/h-03.png'],
                    ] : [
                        ['name' => '接听语音', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/h-f-01.png'],
                        ['name' => '接听视频', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/h-f-02.png'],
                        ['name' => '私信聊天', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/h-f-04.png'],
                        ['name' => '接收礼物', 'icon' => AliyunUtil::IMG_HOST_V2 . 'icons/level/h-f-03.png'],
                    ]
                ]
            ],
            'level_info' => CacheService::getUserLevelSetting($levelType),
        ];
        return $ret;
    }
}
